package com.management.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.management.controller.info.AccountInfo;
import com.management.model.Account;
import com.management.service.AccountService;
import com.management.utils.CopyUtils;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class AccountDetailsServiceImpl implements UserDetailsService {
    @Resource
    private AccountService accountService;
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        Account account = accountService.getOne(new QueryWrapper<Account>().eq("account_loginid", username));
        if (null==account) {
            throw  new UsernameNotFoundException("账号不存在");
        }
        return CopyUtils.CopyOne(account, AccountInfo.class);
    }
}
